package mmoon.mmoonstory.commands;

import mmoon.mmoonstory.interfaces.InitCommand;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;

public class CommandHeal extends CommandBase implements InitCommand {

    public CommandHeal() {
        this.init();
    }

    @Override
    public String getName() {
        return "heal";
    }

    @Override
    public String getUsage(ICommandSender sender) {
        return "heal [int]";
    }

    @Override
    public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
        if (sender instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) sender;
            if (args.length == 0) {
                player.heal(player.getMaxHealth());
            } else if (args.length == 1) {
                player.heal(Float.parseFloat(args[0]));
            } else {
                throw new WrongUsageException(this.getUsage(sender));
            }
        }
    }

    @Override
    public int getRequiredPermissionLevel() {
        return 3;
    }
}
